<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <base th:href="@{/}">
    <meta charset="UTF-8">
    <title>病例列表</title>
    <link rel="stylesheet" th:href="@{/css/bootstrap.min.css}" />
    <link rel="stylesheet" th:href="@{/css/style1.css}" />
    <link rel="stylesheet" th:href="@{/css/style.css}" />
    <script src="/js/jquery.min.js"></script>
    <script type="text/javascript" th:inline="javascript">
        // 处理删除病例的函数
        function deleteRecord(rid) {
            $.ajax({
                url: [[@{/admin/deleteRecord}]],
            type: "post",
                data: {
                id: rid
            },
            success: function (obj) {
                if (obj == "no") {
                    alert("该病例存在关联不允许删除！");
                } else {
                    alert(obj);
                    // 成功删除后刷新网页
                    location.reload();
                }
            },
            error: function () {
                alert("处理删除病例异常！");
            }
        });
        }
    </script>
</head>
<body>
<div th:include="admin/header1"></div>
<main id="main">
    <section class="breadcrumbs">
        <div class="container">
            <div class="d-flex justify-content-between align-items-center">
                <ol>
                    <li><a href="#">首页</a></li>
                    <li><a href="#">病例列表</a></li>
                </ol>
            </div>
        </div>
    </section>
    <section class="inner-page">
        <div class="container">
            <div class="card">
                <div class="card-header">
                    <h3 class="card-title">病例列表</h3>
                </div>
                <div class="card-body">
                    <form th:action="@{admin/recordList}" class="navbar-form navbar-right" style="display: flex;">
                        <div class="form-group" >
                            <input type="text" class="form-control" name="keyword" placeholder="请输入关键词" style="height: 40px; margin-top:-1px ;" />
                        </div>
                        <button type="submit" class="btn " style="margin-top: -1px; height: 40px; margin-left: 10px;background-color: #0accce;color: white" >搜索</button>
                    </form>
                    <div class="table-responsive">
                        <table class="table text-center">
                            <thead>
                            <tr>
                                <th>ID</th>
                                <th>患者姓名</th>
                                <th>身份证号</th>
                                <th>病情</th>
                                <th>医生姓名</th>
                                <th>诊断日期</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody class="text-center">
                            <tr th:each="record : ${records}">
                                <td th:text="${record.id}"></td>
                                <td th:text="${record.name}"></td>
                                <td th:text="${record.cno}"></td>
                                <td th:text="${#strings.abbreviate(record.detail, 20)}"></td>
                                <td th:text="${record.dname}"></td>
                                <td th:text="${record.zdrq}"></td>

                                <td>
<!--                                    <form th:action="@{/admin/toUpdateRecord/{id}(id=${record.id})}" method="get" style="display:inline">-->
<!--                                        <button type="submit" class="btn btn1 btn-sm">编辑</button>-->
<!--                                    </form>-->
                                    <a th:href="'javascript:deleteRecord(' + ${record.id} +')'" class="btn btn2 btn-sm">删除</a>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="8" style="border: none;" class="text-center">
                                    <ul class="pagination justify-content-center">
                                        <li class="page-item" th:if="${currentPage} != 1">
                                            <a class="page-link"
                                               th:href="@{/admin/recordList(currentPage=${currentPage - 1})}">上一页</a>
                                        </li>
                                        <li class="page-item disabled">
                                            <a class="page-link" href="#">第<span
                                                    th:text="${currentPage}"></span>页</a>
                                        </li>
                                        <li class="page-item disabled">
                                            <a class="page-link" href="#">共<span
                                                    th:text="${totalPage}"></span>页</a>
                                        </li>
                                        <li class="page-item" th:if="${currentPage} !=${totalPage}">
                                            <a class="page-link"
                                               th:href="@{/admin/recordList(currentPage=${currentPage + 1})}">下一页</a>
                                        </li>
                                    </ul>
                                </td>
                            </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </section>
</main>
</body>
</html>